package cn.acewill.yxd.yunxundian.utils;

import android.content.Context;
import android.os.Environment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.DiskCache;
import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper;
import com.bumptech.glide.module.GlideModule;

import java.io.File;

/**
 * Created by XXX on 2017/9/6.
 */

public class GlideCache implements GlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        //设置图片的显示格式ARGB_8888(指图片大小为32bit)
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        //设置磁盘缓存目录（和创建的缓存目录相同）
        String path = Environment.getExternalStorageDirectory()
                +"/"+"cn.acewill.yxd"+"/files/ImageCache/";
        final File storageDirectory = new File(path);
        if (!storageDirectory.exists()){
            storageDirectory.mkdirs();
        }
        String downloadDirectoryPath=storageDirectory+"/GlideCache";
        //设置缓存的大小为100M
        final int cacheSize = 100*1000*1000;
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                return DiskLruCacheWrapper.get(storageDirectory, cacheSize);
            }
        });
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}
